package JavaUtils.CSUtils;


import java.lang.reflect.Array;
import java.util.*;

public class CString {
    public final static char cSplit01 = '▅';
    public final static char cSplit02 = '➜';
    public final static char cSplit03 = '✪';
    public final static char cSplit04 = '▌';
    public final static char cSplit05 = '✚';
    public final static char cSplit06 = '〓';
    public final static char cSplit07 = '█';
    public final static char cSplit08 = '◆';
    public final static char cSplit09 = '▲';
    public final static char cSplit10 = '▼';
    public final static char cSplit11 = '✖';
    public final static char cSplit12 = '☰';

    //设置Log颜色字段
    public static String S_SetLogColor(String log, String colorText) {
        //return string.Format("<font size='{0}' color='#{1}'>{2}</font>", fontSize, colorText, ss);//<size=50>www</size>  
        return String.format("#{0}#{1}", colorText, log);
    }

    //获取log颜色字段
    public static String[] S_GetLogColor(String log) {
        String[] sss = new String[2];
        if (log != null && log.length() > 8 && log.charAt(0) == '#' && log.charAt(7) == '#') {
            sss[0] = log.substring(1, 6);
            sss[1] = log.substring(8);
        } else {
            sss[0] = null;
            sss[1] = log;
        }
        return sss;
    }

    public static Boolean IsNullOrEmpty(String str) {
        return str == null || "".equals(str);
    }

//    //多字符拆分--------------
//    public static String[] string_split(String content, char[] split, boolean isClearNull) {
//        List<String> list0 = new ArrayList<>();
//        int stratIndex = 0;
//        for (int a = 0; a < content.length(); a++) {
//            boolean isSplit = false;
//            for (int b = 0; b < split.length; b++) {
//                char a0 = content.charAt(a);
//                char b0 = split[b];
//                if (a0 == b0) {
//                    isSplit = true;
//                    break;
//                }
//            }
//            if (a == content.length() - 1) {
//                isSplit = true;
//            }
//            if (isSplit) {
//                String ss = content.substring(stratIndex, a);
//                stratIndex = a + 1;
//                if (isClearNull) {
//                    ss = ss.trim();
//                    if (ss.length() == 0) {
//                        continue;
//                    }
//                }
//                list0.add(ss);
//            }
//        }
//        String[] array = new String[list0.size()];
//        return list0.toArray(array);
//    }

    //多字符串拆分--------------
    public static String[] string0_split(String content, String split, boolean isClearNull) {
        String[] sss = content.split(split);
        if (!isClearNull) {
            return sss;
        }
        List<String> list = new ArrayList<String>();
        for (String s : sss) {
            if (s.equals("")) {
                continue;
            }
            list.add(s);
        }
        return list.toArray(new String[list.size()]);
    }

    public static String[] string_split(String content, String... split_arr) {
        StringBuilder split = new StringBuilder("[" + split_arr[0]);
        for (int i = 1; i < split_arr.length; i++) {
            split.append("|").append(split_arr[i]);
        }
        split.append("]");
        return string0_split(content, split.toString(), true);
    }

    public static String[] string_split(String content, char... split_arr) {
        StringBuilder split = new StringBuilder("[" + split_arr[0]);
        for (int i = 1; i < split_arr.length; i++) {
            split.append("|").append(split_arr[i]);
        }
        split.append("]");
        return string0_split(content, split.toString(), true);
    }

    public static String toStringLog(Object arr) {
        return toStringLog(arr, 0, Math.min(Array.getLength(arr), 10));
    }

    public static String toStringLog(Object arr, int start, int end) {
        StringBuilder ssb = new StringBuilder();
        ssb.append("(.");
        for (int i = start; i < end; i++) {
            Object obj = Array.get(arr, i);
            if (i == start) {
                ssb.append(obj);
            } else {
                ssb.append("_" + obj);
            }
        }
        ssb.append(".)");
        return ssb.toString();
    }

    public static <T> String toStringLog(T[][] tt) {
        return null;
    }

    public static <K, V> String toStringLog(Map<K, V> map) {
        return null;
    }

    /// <summary>
    /// 是否匹配
    /// </summary>
    public static boolean IsMatching(String assetsPath, String[] matchingArr, int matchingType) {
        String matching = Matching(assetsPath, matchingArr, matchingType);
        return matching != null;
    }

    /// <summary>
    /// 是否匹配
    /// </summary>
    public static String Matching(String assetsPath, String[] matchingArr, int matchingType) {
        if (assetsPath == null) {
            return null;
        }
        if (matchingArr != null && matchingArr.length > 0) {
            for (int i4 = 0; i4 < matchingArr.length; i4++) {
                switch (matchingType) {
                    case 1:
                        if (assetsPath.startsWith(matchingArr[i4])) {
                            return matchingArr[i4];
                        }
                        break;
                    case 2:
                        if (assetsPath.endsWith(matchingArr[i4])) {
                            return matchingArr[i4];
                        }
                        break;
                    case 3:
                        if (assetsPath.contains(matchingArr[i4])) {
                            return matchingArr[i4];
                        }
                        break;
                }
            }
        }
        return null;
    }


    public static void sort_StrList(List<String> list) {
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                if (o1 == null || o2 == null) {
                    return -1;
                }
                if (o1.length() > o2.length()) {
                    return 1;
                }
                if (o1.length() < o2.length()) {
                    return -1;
                }
                if (o1.compareTo(o2) > 0) {
                    return 1;
                }
                if (o1.compareTo(o2) < 0) {
                    return -1;
                }
                if (o1.compareTo(o2) == 0) {
                    return 0;
                }
                return 0;
            }
        });
    }

}
